package com.adminex.controller;

import com.adminex.pojo.User;
import com.adminex.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;


import java.util.ArrayList;
import java.util.List;

@Controller
public class TableController {
    @Autowired
    private UserService userService;
    @GetMapping("basic_table")
    public String basic_table(){
        return "table/basic_table";
    }
    @GetMapping("dynamic_table")
    public String dynamic_table(@RequestParam(value = "pn",defaultValue = "1")Integer pn, Model model){
//        List<User> users = new ArrayList<>();
//        users.add(new User(5,"admin","123456",123456));
//        users.add(new User(6,"abc","7474",123456));
//        users.add(new User(7,"bcd","8585",123456));
//        model.addAttribute("users",users);

        List<User> list = userService.list();
        model.addAttribute("users",list);


        return "table/dynamic_table";
    }
    @GetMapping("responsive_table")
    public String responsive_table(){
        return "table/responsive_table";
    }
    @GetMapping("editable_table")
    public String editable_table(){
        return "table/editable_table";
    }
    @GetMapping("/user/delete/{id}")
    public String deleteUser(@PathVariable("id")int id){
        userService.removeById(id);
        return "redirect:/dynamic_table";
    }
}
